package com.ydzh.kfqgwvisitor.util;

import com.baidu.aip.client.BaseClient;
import com.baidu.aip.http.AipRequest;
import org.json.JSONObject;

import java.util.HashMap;

/**
 * @author zcj
 * @description
 * @date 2021/09/2021/9/8
 **/
public class IdcardUtil extends BaseClient {
    public IdcardUtil(String appId, String apiKey, String secretKey) {
        super(appId, apiKey, secretKey);
    }

    static final String IDCARD = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard";

    public JSONObject idcard(String base64Content, String idCardSide, HashMap<String, String> options) {
        AipRequest request = new AipRequest();
        preOperation(request);

        request.addBody("image", base64Content);

        request.addBody("id_card_side", idCardSide);
        if (options != null) {
            request.addBody(options);
        }
        request.setUri(IDCARD);
        postOperation(request);
        return requestServer(request);
    }
}
